home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Resource / Record Resource Misses < prev    next >
Encoding:
Text File  |  1999-03-04  |  2.9 KB  |  96 lines  |  [TEXT/ToyS]

  1. property sasOnlyIfError : true -- only if -192 is generated
  2.  
  3. property sasLogTitle : "Flavour" & tab & "Num" & tab & "Idx" & tab & "Err" & tab & "Name" & return ¬
  4.     & "------" & tab & "--" & tab & "---" & tab & "---" & tab & "----" & return
  5. property sasLogInfo : "Recorded from "
  6. property sasLogInf2 : " to "
  7. property sasLastApp : "Finder"
  8. property sasProgLoc : {0, 0}
  9. property sasStarted : "Never"
  10. property sasLastDbg : false
  11.  
  12. property sasBreakOn : {"CDEF", "WDEF", "DLOG", "DITL", "CODE"}
  13. property sasBreakOff : {"NFNT"}
  14.  
  15. on run
  16.     -- Start or stop default?
  17.     if (sasStarted is "Never") then
  18.         set defBtn to 2
  19.     else
  20.         set defBtn to 1
  21.     end if
  22.     
  23.     -- Start or stop
  24.     set choice to (display dialog ¬
  25.         "Do you wish to stop or start logging?" buttons {"Stop", "Start"} default button defBtn)
  26.     
  27.     if (the button returned of choice is "Start") then
  28.         -- Last choice?
  29.         if (sasLastDbg) then
  30.             set defBtn to 2
  31.         else
  32.             set defBtn to 3
  33.         end if
  34.         
  35.         -- Get app name
  36.         set choice to (display dialog ¬
  37.             "Record resource erros for application:" default answer ¬
  38.             sasLastApp buttons {"Cancel", "With Debugger", "OK"} default button defBtn)
  39.         
  40.         -- Set app for independent agent
  41.         set sasLastApp to text returned of choice
  42.         set sasLastDbg to (the button returned of choice is not "OK")
  43.         
  44.         record resource misses for sasLastApp ¬
  45.             break when missing sasLastDbg ¬
  46.             except when flavour is one of sasBreakOff ¬
  47.             breaking when flavour is one of sasBreakOn ¬
  48.             error watching sasOnlyIfError
  49.         
  50.         -- Store start date
  51.         set sasStarted to the clock in extended sortable form
  52.     else
  53.         -- Get log
  54.         set logResults to (record resource misses for "")
  55.         
  56.         -- Get count and set index
  57.         set n to 1
  58.         set cnt to the number of items in logResults
  59.         
  60.         -- New progress window
  61.         set pgWin to display progress titled ¬
  62.             "Saving Log" maximum cnt + 1 located at sasProgLoc
  63.         
  64.         -- Open log file on desktop
  65.         display progress pgWin labeled "Opening file…"
  66.         
  67.         set logFile to open fork from (path to desktop) ¬
  68.             named "ResError Log" of type "TEXT" of creator ¬
  69.             "R*ch" with write access and appending
  70.         
  71.         -- Add a blank line if we are appending
  72.         if ((size fork logFile) > 0) then write data to logFile given «class Text»:return
  73.         
  74.         -- Write header data
  75.         display progress pgWin labeled "Writing header…" value n
  76.         write data to logFile given «class Text»:(sasLogInfo & sasStarted & sasLogInf2 & (the clock in extended sortable form) & return & return & sasLogTitle)
  77.         
  78.         -- Write the entries
  79.         display progress pgWin labeled "Writing " & cnt & " entries…" value n
  80.         
  81.         repeat with logItem in logResults
  82.             -- display dialog logItem buttons {"OK"} default button 1
  83.             display progress pgWin value n
  84.             write data to logFile given «class Text»:(logItem & return)
  85.             set n to n + 1
  86.         end repeat
  87.         
  88.         -- Close window and file
  89.         set sasProgLoc to screen location of (display progress pgWin labeled "Closing…")
  90.         close fork logFile
  91.         display progress pgWin with disposal
  92.         
  93.         set sasStarted to "Never"
  94.     end if
  95. end run
  96.